/****************************************************************************
 * Copyright (C) 2009 SciTouch LLC
 * 
 * This file is part of Indigo toolkit.
 * 
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 3 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 ***************************************************************************/

#include "base_cpp/output.h"
#include "molecule/molecule_ring_canonizer.h"
#include "molecule/molecule.h"

MoleculeRingCanonizer::MoleculeRingCanonizer ()
{
   cb_vertex_rank = _vertex_rank;
   cb_vertex_code = _vertex_code;
   cb_edge_code = _edge_code;
   cb_edge_rank = _edge_rank;
}

void MoleculeRingCanonizer::edgeCodesOff ()
{
   cb_edge_code = 0;
   cb_edge_rank = 0;
}

int MoleculeRingCanonizer::_vertex_rank (const Graph &ring, int vertex_idx)
{
   const Molecule &mol = (const Molecule &)ring;

   return mol.getAtom(vertex_idx).label;
}

int MoleculeRingCanonizer::_edge_rank (const Graph &ring, int edge_idx)
{
   const Molecule &mol = (const Molecule &)ring;

   return mol.getBond(edge_idx).type;
}

void MoleculeRingCanonizer::_vertex_code (const Graph &ring, int vertex_idx, Output &output)
{
   output.writeString(Element::toString(((const Molecule &)ring).getAtom(vertex_idx).label));
}

void MoleculeRingCanonizer::_edge_code (const Graph &ring, int edge_idx, Output &output)
{
   const Molecule &mol = (const Molecule &)ring;

   int type = mol.getBond(edge_idx).type;

   if (type == BOND_SINGLE)
      output.writeChar('-');
   else if (type == BOND_DOUBLE)
      output.writeChar('=');
   else if (type == BOND_TRIPLE)
      output.writeChar('#');
   else
      output.writeChar('%');
}
